$$ = function(id){
	return document.getElementById(id);
}
$(function(){
	//返回按钮
	$('.c-share-back').click(function(){
		let funcstr = $(this).attr('data-func');
		if(typeof funcstr == 'undefined'){
			history.go(-1);
		}else{
			var func = window[funcstr];
			if(typeof func == 'function'){
				//特例
				func();
			}else{
				//默认
				history.go(-1);
			}
		}
	});
	
	$("input[type='text'],input[type='tel']").attr('autocomplete','off');
});


//发送标准Ajax请求
function AjaxJson(p_url,p_data,p_success,p_error,p_complete){
	$.ajax({
		url : p_url,
		type : 'POST',
		dataType : 'JSON',
		data : p_data,
		success : function(e){
			if(p_success){
				p_success(e);
			}
		},error : function(){
			if(p_error){
				p_error();
			}
		},complete : function(){
			if(p_complete){
				p_complete();
			}
		}
	})
}
//校验上级货款余额
function CheckHuoKuanPayAmout(amount,success,checktype,orderid){
	let msgHTML = '<div class="g-reset-fixed g-notice-2 checkxxpayshow" style="display:none0"><div class="g-bg-fixed"></div><div class="g-fixed-mid g-pd g-flex g-fd-c" style="overflow-y: auto; padding-bottom: 20px; width: 80%; max-height: 75%; border-radius: 20px;"><p class="g-bb g-tc g-pd g-fs-34">提示</p><div class="g-scroll-container"><div><div class="g-pd-lr g-bb g-m-t-20 g-m-b-20" style="padding-bottom:20px;"><p class="g-orange-dark g-fs-28">MESSAGE</p></div><div style="max-height: 460px; overflow-y: auto;"><div><div class="g-pd-lr g-m-t-20 g-m-b-20 g-fs-28"><p class="g-m-tb">上级代理：AGENTNAME</p><p class="g-m-tb">上级电话：<a style="color:#5c8dff;text-decoration:none" href="tel://AGENTPHONENUM">AGENTPHONENUM</a></p></div></div></div></div></div><div class="g-btn-blue g-m-b-20 checkxxpayclose" style="margin-top: 40px;">确定</div></div></div>';
	
	let pd = {
		'amount' : amount,
		'checktype' : checktype ? checktype : 1, //代理升级专用
		'orderid' : orderid ? orderid : ''
	}
	AjaxJson("/checkhuokuanpay",pd,function(e){
		if(e.flag){
			success(e);
		}else{
			$('.checkxxpayshow').remove();
			let html = msgHTML.replace(/AGENTNAME/g,e.data.agentname).replace(/MESSAGE/g,e.info);
				html = html.replace(/AGENTPHONENUM/g,e.data.phonenum);
			$('body').append(html);
			$('.checkxxpayclose').click(function(){
				$('.checkxxpayshow').css('display','none').remove();
			});
		}
	},function(){ } ,function(){ });
}

//微信支付金额上线校验
function CheckWePayAmout(amount,success){
	let msgHTML = '<div class="g-reset-fixed g-notice-2 checkxxpayshow" style="display:none0"><div class="g-bg-fixed"></div><div class="g-fixed-mid g-pd g-flex g-fd-c" style="overflow-y: auto; padding-bottom: 20px; width: 80%; max-height: 75%; border-radius: 20px;"><p class="g-bb g-tc g-pd g-fs-34">提示</p><div class="g-scroll-container"><div><div class="g-pd-lr g-bb g-m-t-20 g-m-b-20" style="padding-bottom:20px;"><p class="g-orange-dark g-fs-28">MESSAGE</p></div></div></div><div class="g-btn-blue g-m-b-20 checkxxpayclose" style="margin-top: 40px;">确定</div></div></div>';
	let pd = {
		'amount' : amount,
	}
	AjaxJson("/checkwepay",pd,function(e){
		if(e.flag){
			success(e);
		}else{
			$('.checkxxpayshow').remove();
			let html = msgHTML.replace(/AGENTNAME/g,e.data.agentname).replace(/MESSAGE/g,e.info);
				html = html.replace(/AGENTPHONENUM/g,e.data.phonenum);
			$('body').append(html);
			$('.checkxxpayclose').click(function(){
				$('.checkxxpayshow').css('display','none').remove();
			});
		}
	},function(){ } ,function(){ });
}



